/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RekamMedis.java
 *
 * Created on Oct 7, 2012, 3:33:55 PM
 */
package View;

import Controller.ControlData;
import Data.Pasien;
import Data.RekamMedisData;
import Data.Resep;
import TableModel.RekamMedisTableModel;
import TableModel.pasienTableModel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author a9uszT
 */
public class RekamMedis extends javax.swing.JFrame {

    /**
     * Creates new form RekamMedis
     */
    public RekamMedis() {
        initComponents();

        tampilTable();
//        tampilTableRM();
        GregorianCalendar gc = new GregorianCalendar();
        tanggalRM.setDate(gc.getTime());
        cari_internalFrame.setVisible(false);
        namaPetugas.setEnabled(false);
        namaPetugas.setEditable(false);
        idPetugasRM.setEnabled(false);
        idPetugasRM.setEditable(false);
        nama_TF.setEditable(false);
        nama_TF.setEnabled(false);
        fak_TF.setEditable(false);
        fak_TF.setEnabled(false);
        anamnesa_button.setEnabled(true);
        disableform();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        delete_item = new javax.swing.JMenuItem();
        cari_internalFrame = new javax.swing.JInternalFrame();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        cariRM_TF = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        pasien_table = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        noRM_TF = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        nama_TF = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        fak_TF = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        rekammedis_table = new javax.swing.JTable();
        anamnesa_button = new javax.swing.JButton();
        diagnosa_button = new javax.swing.JButton();
        therapi_button = new javax.swing.JButton();
        resep_button = new javax.swing.JButton();
        exit_button = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        namaPetugas = new javax.swing.JTextField();
        idPetugasRM = new javax.swing.JTextField();
        tanggalRM = new com.toedter.calendar.JDateChooser();
        jLabel11 = new javax.swing.JLabel();
        otomatis_rm = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        idDokterRM = new javax.swing.JTextField();
        namaDokter = new javax.swing.JTextField();
        LDOC = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();

        delete_item.setText("Delete");
        delete_item.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delete_itemActionPerformed(evt);
            }
        });
        jPopupMenu1.add(delete_item);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cari_internalFrame.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        cari_internalFrame.setVisible(true);

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel13.setText("Pencarian Pasien");

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel14.setText("kata kunci pencarian");

        cariRM_TF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                cariRM_TFKeyReleased(evt);
            }
        });

        pasien_table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "id", "nama", "alamat", "umur", "jenis Kelamin", "no telp", "fakultas/bag"
            }
        ));
        pasien_table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pasien_tableMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(pasien_table);

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jButton1.setText("keluar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout cari_internalFrameLayout = new javax.swing.GroupLayout(cari_internalFrame.getContentPane());
        cari_internalFrame.getContentPane().setLayout(cari_internalFrameLayout);
        cari_internalFrameLayout.setHorizontalGroup(
            cari_internalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cari_internalFrameLayout.createSequentialGroup()
                .addContainerGap(190, Short.MAX_VALUE)
                .addComponent(jLabel14)
                .addGap(18, 18, 18)
                .addComponent(cariRM_TF, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(286, 286, 286))
            .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 754, Short.MAX_VALUE)
            .addGroup(cari_internalFrameLayout.createSequentialGroup()
                .addGap(348, 348, 348)
                .addComponent(jButton1)
                .addContainerGap(331, Short.MAX_VALUE))
            .addGroup(cari_internalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 754, Short.MAX_VALUE))
        );
        cari_internalFrameLayout.setVerticalGroup(
            cari_internalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cari_internalFrameLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel13)
                .addGap(18, 18, 18)
                .addGroup(cari_internalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cariRM_TF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 111, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(104, 104, 104))
            .addGroup(cari_internalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cari_internalFrameLayout.createSequentialGroup()
                    .addContainerGap(98, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(98, Short.MAX_VALUE)))
        );

        getContentPane().add(cari_internalFrame, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 180, 770, 350));

        jPanel1.setBackground(new java.awt.Color(0, 153, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "rekam medis", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), java.awt.Color.white)); // NOI18N
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Rekam Medis");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(106, 16, 610, 27));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel4.setText("Id Rekam Medis");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 50, -1, -1));

        noRM_TF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                noRM_TFActionPerformed(evt);
            }
        });
        noRM_TF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                noRM_TFKeyReleased(evt);
            }
        });
        jPanel1.add(noRM_TF, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 80, 70, -1));

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel5.setText("Tanggal");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(16, 49, -1, -1));

        nama_TF.setEnabled(false);
        jPanel1.add(nama_TF, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 80, 160, -1));

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel6.setText("Fak/Bag");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, -1, -1));

        fak_TF.setToolTipText("");
        fak_TF.setEnabled(false);
        jPanel1.add(fak_TF, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 110, 160, -1));

        rekammedis_table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "IDrekamMedis", "tanggal rekam medis", "Anamnesa", "Diagnosa", "Therapi", "resep", "idPetugas", "idDokter"
            }
        ));
        rekammedis_table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                rekammedis_tableMouseReleased(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rekammedis_tableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(rekammedis_table);
        rekammedis_table.getColumnModel().getColumn(1).setResizable(false);
        rekammedis_table.getColumnModel().getColumn(2).setResizable(false);
        rekammedis_table.getColumnModel().getColumn(3).setResizable(false);
        rekammedis_table.getColumnModel().getColumn(4).setResizable(false);
        rekammedis_table.getColumnModel().getColumn(5).setResizable(false);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(6, 161, 830, 113));

        anamnesa_button.setFont(new java.awt.Font("Arial Black", 1, 14));
        anamnesa_button.setText("Anamnesa");
        anamnesa_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                anamnesa_buttonActionPerformed(evt);
            }
        });
        jPanel1.add(anamnesa_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 340, -1, 36));

        diagnosa_button.setFont(new java.awt.Font("Arial Black", 1, 14));
        diagnosa_button.setText("Diagnosa");
        diagnosa_button.setEnabled(false);
        diagnosa_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                diagnosa_buttonActionPerformed(evt);
            }
        });
        jPanel1.add(diagnosa_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 340, -1, 36));

        therapi_button.setFont(new java.awt.Font("Arial Black", 1, 14));
        therapi_button.setText("Therapi");
        therapi_button.setEnabled(false);
        therapi_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                therapi_buttonActionPerformed(evt);
            }
        });
        jPanel1.add(therapi_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 340, -1, 36));

        resep_button.setFont(new java.awt.Font("Arial Black", 1, 14));
        resep_button.setText("Resep");
        resep_button.setEnabled(false);
        resep_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resep_buttonActionPerformed(evt);
            }
        });
        jPanel1.add(resep_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 340, -1, 36));

        exit_button.setFont(new java.awt.Font("Arial Black", 1, 14));
        exit_button.setText("Keluar");
        exit_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exit_buttonActionPerformed(evt);
            }
        });
        jPanel1.add(exit_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(730, 340, -1, 36));

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel10.setText("id Petugas-NamaPetugas");
        jPanel1.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 110, -1, -1));
        jPanel1.add(namaPetugas, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 110, 110, -1));
        jPanel1.add(idPetugasRM, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 110, 50, -1));

        tanggalRM.setEnabled(false);
        jPanel1.add(tanggalRM, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 40, 160, 30));

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel11.setText("Nama");
        jPanel1.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 80, -1, -1));

        otomatis_rm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                otomatis_rmActionPerformed(evt);
            }
        });
        otomatis_rm.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                otomatis_rmKeyReleased(evt);
            }
        });
        jPanel1.add(otomatis_rm, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 50, 170, -1));

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel12.setText("Id Pasien");
        jPanel1.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, -1, -1));
        jPanel1.add(idDokterRM, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 80, 50, -1));
        jPanel1.add(namaDokter, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 80, 110, -1));

        LDOC.setFont(new java.awt.Font("Tahoma", 1, 14));
        LDOC.setText("id Dokter-NamaDokter");
        jPanel1.add(LDOC, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 80, -1, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 170, 850, 400));

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 30));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Sistem Informasi Rekam Medis");
        jPanel3.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 20, 490, 50));

        jLabel2.setBackground(new java.awt.Color(255, 255, 255));
        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Poliklinik Sanata Dharma");
        jPanel3.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 70, -1, 28));

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel15.setForeground(new java.awt.Color(255, 255, 255));
        jLabel15.setText("Jl. paingan, Maguwoharjo");
        jPanel3.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 110, -1, -1));

        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/picture/usd.gif"))); // NOI18N
        jPanel3.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 10, 150, 140));

        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/picture/Vista_Blue_Withoutlogo_1600x1200.jpg"))); // NOI18N
        jLabel17.setText("jLabel10");
        jPanel3.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 850, 170));

        getContentPane().add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 860, -1));

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </editor-fold>//GEN-END:initComponents

    private void diagnosa_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diagnosa_buttonActionPerformed
//        diagnosa diag = new diagnosa();
//        diag.setVisible(true);
//        diag.setMenuowner(this);
//        diag.setParent(this);
    }//GEN-LAST:event_diagnosa_buttonActionPerformed

    private void therapi_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_therapi_buttonActionPerformed
//        Therapi th = new Therapi();
//        th.setVisible(true);
//        th.setMenuowner(this);
//        th.setParent(this);
    }//GEN-LAST:event_therapi_buttonActionPerformed

    private void resep_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resep_buttonActionPerformed
//        Date tgl = tanggalRM.getDate();
//        SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy");
//        String tanggal = sdf.format(tgl);
//        String idResep = otomatis_rm.getText();
//        System.out.println(idResep);
//        String idPasien = noRM_TF.getText();
//
//        Resep res = new Resep();
//        res.setIdResep(idResep);
//        res.setTanggalResep(tanggal);
//        RekamMedisData rmd = new RekamMedisData();
//        rmd.setResep(res);
//        rmd.setIdRekamMedis(idResep);
//        rmd.setTanggal_RM(tanggal);
//        try {
//            ControlData.getKoneksi().addResep(res);
//        } catch (Exception ex) {
//            Logger.getLogger(RekamMedis.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        try {
//            ControlData.getKoneksi().updateIDresep(rmd);
//        } catch (Exception e) {
//        }
//        resepObat ro = new resepObat();
//        resepObat.idPasienTF.setText(idPasien);
//        resepObat.idResepTF.setText(idResep);
//        ro.setVisible(true);
    }//GEN-LAST:event_resep_buttonActionPerformed

    private void exit_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exit_buttonActionPerformed
        JOptionPane.showMessageDialog(rootPane, "selesai ");
        dispose();
    }//GEN-LAST:event_exit_buttonActionPerformed

    private void noRM_TFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noRM_TFActionPerformed

        try {
            String iddata = noRM_TF.getText();
            Pasien b = ControlData.getSelectedPasien(iddata);
//            tampilTableRM();
            if (b != null) {
                String nama = b.getNama();
                String fakt = b.getFakultas();
                nama_TF.setText(nama);
                fak_TF.setText(fakt);
                noRMotomatis();
                diagnosa_button.setEnabled(true);
            } else {
                int status = JOptionPane.showConfirmDialog(rootPane, "cari dalam list tabel ? ",
                        "search", JOptionPane.YES_NO_OPTION);
                if (status == 0) {
                    cari_internalFrame.setVisible(true);
                    if (idPetugasRM.getText().equalsIgnoreCase("") == true) {
//                        tampilTableRMSkrng();
                        diagnosa_button.setEnabled(true);
                    } else {
                        tampilTable();
                    }
                }
            }
//            tampilTableRM();

        } catch (Exception ex) {
            Logger.getLogger(RekamMedis.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_noRM_TFActionPerformed

    private void anamnesa_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_anamnesa_buttonActionPerformed
        Anamnesa an = new Anamnesa();
        an.setVisible(true);
        an.setMenuowner(this);
//        this.setEnabled(false);
        an.setParent(this);
    }//GEN-LAST:event_anamnesa_buttonActionPerformed

    private void cariRM_TFKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cariRM_TFKeyReleased
        String key = cariRM_TF.getText();
        try {
            List<Pasien> search = ControlData.ResultPasienSelected(key);
            pasienTableModel brngTableModel = new pasienTableModel(search);
            pasien_table.setModel(brngTableModel);
        } catch (Exception ex) {
            Logger.getLogger(Registrasi.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cariRM_TFKeyReleased

    private void pasien_tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pasien_tableMouseClicked
        int row = pasien_table.getSelectedRow();
        String id = pasien_table.getValueAt(row, 0).toString();
        String nama = pasien_table.getValueAt(row, 1).toString();
        String fakt = pasien_table.getValueAt(row, 6).toString();
        noRM_TF.setText(id);
        nama_TF.setText(nama);
        fak_TF.setText(fakt);
        cari_internalFrame.setVisible(false);
//        tampilTableRM();
        if (idPetugasRM.getText().matches("")) {
//            noRMotomatisDokter();
//            tampilTableRM();

        } else if (!idPetugasRM.getText().matches("")) {
//            noRMotomatis();
//            tampilTableRM();
        }
    }//GEN-LAST:event_pasien_tableMouseClicked

    private void noRM_TFKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_noRM_TFKeyReleased
//        tampilTableRM();
//        anamnesa_button.setEnabled(true);
    }//GEN-LAST:event_noRM_TFKeyReleased

    private void otomatis_rmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_otomatis_rmActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_otomatis_rmActionPerformed

    private void otomatis_rmKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_otomatis_rmKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_otomatis_rmKeyReleased

    private void rekammedis_tableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rekammedis_tableMouseReleased
        if (namaPetugas.getText().equalsIgnoreCase("") == true) {
            if (evt.isPopupTrigger()) {
                jPopupMenu1.show(rekammedis_table, evt.getX(), evt.getY());
            }
        }

    }//GEN-LAST:event_rekammedis_tableMouseReleased

    private void delete_itemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delete_itemActionPerformed
//        int status = JOptionPane.showConfirmDialog(rootPane, "yakin hapus ?",
//                "delete", JOptionPane.YES_NO_OPTION);
//        if (status == 0) {
//            String id = otomatis_rm.getText();
//            RekamMedisData kt = new RekamMedisData();
//            kt.setIdRekamMedis(id);
//            try {
//                ControlData.getKoneksi().deleteRM(kt);
//                JOptionPane.showMessageDialog(rootPane, "data berhasil hapus");
//                tampilTableRM();
//            } catch (Exception ex) {
//                JOptionPane.showMessageDialog(rootPane, "data barang gagal DIHAPUS " + " \n TERJADI error ");
//                ex.getMessage();
//
//            }
//        }
    }//GEN-LAST:event_delete_itemActionPerformed

    private void rekammedis_tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rekammedis_tableMouseClicked
        int row = rekammedis_table.getSelectedRow();
        String id = rekammedis_table.getValueAt(row, 0).toString();
    }//GEN-LAST:event_rekammedis_tableMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        cari_internalFrame.setVisible(false);
        cari_internalFrame.revalidate();
    }//GEN-LAST:event_jButton1ActionPerformed
    private void tampilTable() {
        try {
            List<Pasien> lkat = ControlData.getAllPasien();
            pasienTableModel KTM = new pasienTableModel(lkat);
            pasien_table.setModel(KTM);
        } catch (Exception ex) {
            Logger.getLogger(RekamMedis.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

//    private void tampilTableRMSkrng() {
//        Date tgl = tanggalRM.getDate();
//        SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy");
//        String tanggal = sdf.format(tgl);
//        try {
//            List<Pasien> lkat = ControlData.getAllPasienRMSkrng(tanggal);
//            pasienTableModel KTM = new pasienTableModel(lkat);
//            pasien_table.setModel(KTM);
//        } catch (Exception ex) {
//            Logger.getLogger(RekamMedis.class.getName()).log(Level.SEVERE, null, ex);
//        }
//    }
//
    public final void tampilTableRM() {
        try {
            List<RekamMedisData> lkat = ControlData.getAllRMPasien(noRM_TF.getText());
            RekamMedisTableModel KTM = new RekamMedisTableModel(lkat);
            rekammedis_table.setModel(KTM);
        } catch (Exception ex) {
            Logger.getLogger(RekamMedis.class.getName()).log(Level.SEVERE, null, ex);
        }
        diagnosa_button.setEnabled(true);
        ControlData.db.close();
    }
//    private void automaticNumber() {
//        try {
//            Date tgl = tanggalRM.getDate();
//            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy");
//            String tanggal = sdf.format(tgl);
//
//            String a = ControlData.getKoneksi().nomorBaruResep(tanggal);
//            if (a.equals("null")) {
//                a = "001";
//            } else if (a.length() == 1) {
//                a = "00" + a;
//            } else if (a.length() == 2) {
//                a = "0" + a;
//            }
//            String idPasien = ControlData.getKoneksi().cariKodePasien(nama_TF.getText());
//            String idResep = idPasien + a;
//            Resep res = new Resep();
//            res.setIdResep(idResep);
//            res.setTanggalResep(tanggal);
//            ControlData.getKoneksi().addResep(res);
//            RekamMedisData rmd = new RekamMedisData();
//            rmd.setResep(res);
//            rmd.setIdRekamMedis(idPasien);
//            rmd.setTanggal_RM(tanggal);
//            ControlData.getKoneksi().updateIDresep(rmd);
//            resepObat ro = new resepObat();
//            resepObat.idPasienTF.setText(idPasien);
//            resepObat.idResepTF.setText(idResep);
//            ro.setVisible(true);
//
//        } catch (Exception ex) {
//            Logger.getLogger(RekamMedis.class.getName()).log(Level.SEVERE, null, ex);
//        }
//
//    }
    public static void noRMotomatis() {
        try {
            String id = noRM_TF.getText();
            String a = ControlData.kodeRM(id);
            if (a.equals("null")) {
                a = "001";
            } else if (a.length() == 1) {
                a = "00" + a;
            } else if (a.length() == 2) {
                a = "0" + a;
            }
            String rmnew = id.substring(1);
            otomatis_rm.setText(rmnew);
        } catch (Exception ex) {
            Logger.getLogger(RekamMedis.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
//    public void noRMotomatisDokter() {
//        try {
//            String id = noRM_TF.getText();
//            String a = ControlData.getKoneksi().nomorBaruRMD(id);
//            if (a.equals("null")) {
//                a = "001";
//            } else if (a.length() == 1) {
//                a = "00" + a;
//            } else if (a.length() == 2) {
//                a = "0" + a;
//            }
//            String rmnew = id + a;
//            otomatis_rm.setText(rmnew);
//        } catch (Exception ex) {
//            Logger.getLogger(RekamMedis.class.getName()).log(Level.SEVERE, null, ex);
//        }
//    }
    private void disableform() {
        jLabel10.setVisible(false);
        idPetugasRM.setVisible(false);
        namaPetugas.setVisible(false);
        LDOC.setVisible(false);
        idDokterRM.setVisible(false);
        namaDokter.setVisible(false);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(RekamMedis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(RekamMedis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(RekamMedis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(RekamMedis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new RekamMedis().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JLabel LDOC;
    public static javax.swing.JButton anamnesa_button;
    private javax.swing.JTextField cariRM_TF;
    private javax.swing.JInternalFrame cari_internalFrame;
    private javax.swing.JMenuItem delete_item;
    public static javax.swing.JButton diagnosa_button;
    private javax.swing.JButton exit_button;
    public static javax.swing.JTextField fak_TF;
    public static javax.swing.JTextField idDokterRM;
    public static javax.swing.JTextField idPetugasRM;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    public static javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    public static javax.swing.JTextField namaDokter;
    public static javax.swing.JTextField namaPetugas;
    public static javax.swing.JTextField nama_TF;
    public static javax.swing.JTextField noRM_TF;
    public static javax.swing.JTextField otomatis_rm;
    private javax.swing.JTable pasien_table;
    private javax.swing.JTable rekammedis_table;
    public static javax.swing.JButton resep_button;
    private com.toedter.calendar.JDateChooser tanggalRM;
    public static javax.swing.JButton therapi_button;
    // End of variables declaration//GEN-END:variables
}
